//
//  MXPublishController.m
//  CatchBear
//
//  Created by 王启颖 on 2019/1/27.
//  Copyright © 2019 王启颖. All rights reserved.
//

#import "MXPublishController.h"
#import "MXPublishView.h"

@interface MXPublishController ()
@property (nonatomic, strong) NSMutableArray                *imageList;
@property(strong,nonatomic)MXPublishView *publishView;
@end

@implementation MXPublishController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self publishView];
}

- (void)loadView{
    [super loadView];
    self.view.backgroundColor = [UIColor whiteColor];
    [self addHeadView];
}

- (void)addHeadView{
    self.title = @"签到";
    [self barButtonItemName:@"上一步" withImageName:nil targer:@"backViewController" isRight:NO];
    [self barButtonItemName:@"完成" withImageName:nil targer:@"nextOperation" isRight:YES];
}

/**
 TODO:返回
 */
- (void)backViewController{
    [self.navigationController popViewControllerAnimated:YES];;
}

/**
 TODO:下一步
 */
- (void)nextOperation{
    [self.publishView publishClick];
}

//添加BarButtonItem
- (UIButton *)barButtonItemName:(NSString *)name withImageName:(NSString *)imageName targer:(NSString *)targerName isRight:(BOOL)right
{
    [super barButtonItemName:name withImageName:imageName targer:targerName isRight:right];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 50,50);
    if (![NSString isEmpty:name]) {
        [button setTitle:name forState:UIControlStateNormal];
        button.titleLabel.font = FONTSIZE(16);
        [button setTitleColor:MX_TEXT1_COLOR forState:UIControlStateNormal];
    }
    if (![NSString isEmpty:imageName]) {
        [button setImage:[UIImage imageNamed:imageName]  forState:UIControlStateNormal];
        
    }
    if (![NSString isEmpty:targerName]) {
        SEL action = NSSelectorFromString(targerName);
        [button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
        
    }
    if (right) {
        [button setTitleColor:MX_SECONDARY_COLOR forState:UIControlStateNormal];
        button.backgroundColor = MX_MAIN_COLOR;
        button.frame = CGRectMake(0, 13, 60,25);
        [button changeCornerRadius:5];
        
        if (![NSString isEmpty:imageName] && [NSString isEmpty:name]) {
            button.imageEdgeInsets  = UIEdgeInsetsMake(0, 30, 0, 0);
        }
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    }else
    {
        if (![NSString isEmpty:imageName] && [NSString isEmpty:name]) {
            button.imageEdgeInsets  =  UIEdgeInsetsMake(0, -30, 0, 0);
        }
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    }
    return button;
}

#pragma mark - 懒加载 -
-(MXPublishView *)publishView{
    if (!_publishView) {
        
        MXPublishView *view = [[MXPublishView alloc]initWithFrame:self.view.bounds];
        _publishView = view;
        _publishView.navigationController = self.navigationController;
        _publishView.lastSelectAssets = self.lastSelectAssets;
        _publishView.publishImage = self.publishImage;
        [self.view addSubview:_publishView];
    }
    return _publishView;
}


@end
